//
//  ExamplePhotoView.m
//  跨界收
//
//  Created by Allen on 2018/11/20.
//  Copyright © 2018年 gztx. All rights reserved.
//

#import "ExamplePhotoView.h"

@implementation ExamplePhotoView

- (instancetype)initWithFrame:(CGRect)frame withArray:(NSArray *)contentArray imageArray:(NSArray *)imageArray
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        _contentArray = contentArray;
        _imageArray = imageArray;
        [self initImageViewItem];
    }
    return self;
}
- (void)initImageViewItem
{
    UILabel *sectionLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 200, 30)];
    sectionLabel.textColor = [UIColor lightGrayColor];
    sectionLabel.text = @"实例照片";
    sectionLabel.font = [UIFont systemFontOfSize:15.0];
    [self addSubview:sectionLabel];
    
    CGFloat distance = 0;
    CGFloat width = 150;
    CGFloat height = 90;
    if (_contentArray.count == 1) {
        distance = 20;
        width = SCREEN_WIDTH-20*2;
        height = 160;
        UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(distance, 30, width, height)];
        imageview.contentMode = UIViewContentModeScaleAspectFit;
        imageview.image = [UIImage imageNamed:_imageArray[0]];
        UILabel *contentLabel = [self creatContentLabel];
        contentLabel.frame = CGRectMake(distance, 95, width, 30);
        contentLabel.text = _contentArray[0];
        [self addSubview:contentLabel];
        [self addSubview:imageview];
        
    }else{
        distance = 20;
        width = (SCREEN_WIDTH-20*3)/2.0;
        height = 90;
        for (int i = 0; i < _contentArray.count; i++) {
            CGFloat Y = i/2 *(height + 10)+30;
            CGFloat X = i%2 *(width + distance) + distance;
            UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(X, Y, width, height)];
            imageview.image = [UIImage imageNamed:_imageArray[i]];
            imageview.tag = 100+i;
            UILabel *contentLabel = [self creatContentLabel];
            contentLabel.frame = CGRectMake(X, Y+75, width, 30);
            contentLabel.center = imageview.center;
            contentLabel.text = _contentArray[i];
            contentLabel.tag = 200+i;
            [self addSubview:imageview];
            [self addSubview:contentLabel];
        }
    }
}
- (UILabel *)creatContentLabel
{
    UILabel *contentLabel = [[UILabel alloc]init];
    contentLabel.textColor = [UIColor whiteColor];
    contentLabel.font = [UIFont systemFontOfSize:15.0];
    contentLabel.textAlignment = NSTextAlignmentCenter;
    contentLabel.backgroundColor = [UIColor clearColor];
    return contentLabel;
}
@end
